package com.aierjun.idcardorclib;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Created by Ani_aierJun on 2017/9/27.
 */

public class FileUtils {
    public static String sdPath = Environment.getExternalStorageDirectory() + "/qiche/tessdata";
    public static String tessPath =  Environment.getExternalStorageDirectory() + "/qiche";
    public static boolean copyAssetFile(Context context,String name) throws Exception {
        String filePath = sdPath + "/" + name;
        File f = new File(sdPath);
        if (f.exists()) {
        } else {
            f.mkdirs();
        }
        File dataFile = new File(filePath);
        if (dataFile.exists()) {
            return true;// 文件存在
        } else {

            InputStream in = context.getAssets().open(name);

            File outFile = new File(filePath);
            if (outFile.exists()) {
                outFile.delete();
            }
            OutputStream out = new FileOutputStream(outFile);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        }

        return false;
    }

}
